package cz.muni.fi.pa165.musiclibrary.implejb.database.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.commons.lang3.Validate;
import org.joda.time.LocalDate;

import cz.muni.fi.pa165.musiclibrary.api.database.entity.IAlbum;
import cz.muni.fi.pa165.musiclibrary.implejb.database.entity.Album;

/**
 *
 * @author Maros Kucbel
 * @date 2012-11-09T20:30:55+0100
 */
@Stateless
public class AlbumDAO implements AlbumDAOLocal {

    private EntityManager entityManager;
    
    @PersistenceContext
    public void setEntityManager(final EntityManager entityManager) {
        this.entityManager = entityManager;
    }
    
    @Override
    public void create(IAlbum album) {
        Validate.isTrue(album != null, "Album should not be null.");
        Validate.isTrue(album.getIdAlbum() == null, "Album identifier should be null.");
        
        this.entityManager.persist(album);
    }

    @Override
    public void update(IAlbum album) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void delete(IAlbum album) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public IAlbum getById(Long id) {
        Validate.isTrue(id != null, "Identifier should not be null.");
        final Album album = entityManager.find(Album.class, id);
        return album;
    }

    @Override
    public List<IAlbum> getAll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<IAlbum> getByTitle(String title) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<IAlbum> getByReleaseDate(LocalDate date) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
}
